package com.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.common.constant.SharesConstan;
import com.common.utils.DateUtil;
import com.common.utils.HttpClient5Utils;
import com.common.utils.MeUtils;
import com.entity.*;
import com.mapper.SharesDataMapper;
import com.service.*;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.vo.SharesZdfVo;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.*;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @since 2021-11-02
 */
@Service
public class SharesDataServiceImpl
        extends ServiceImpl<SharesDataMapper, SharesData>
        implements SharesDataService {

    @Autowired
    private SharesDetailService sharesDetailService;

    @Autowired
    private CodeCjlService codeCjlService;

    @Autowired
    private HintSharesService hintSharesService;

    @Autowired
    private HintNumService hintNumService;

    /**
     * //             22开始，倒数
     * //            vo.setD(split[0]);     //日期
     * //            vo.setO(new BigDecimal(split[1]));//开盘价
     * //            vo.setC(new BigDecimal(split[2]));//收盘价
     * //            vo.setH(new BigDecimal(split[3]));//最高价
     * //            vo.setL(new BigDecimal(split[4]));//最低价
     * //            vo.setV(new BigDecimal(split[5]));//成交量
     */
    @Override
    public  List<SharesData> saveCjl(List<Object> parse, String szorsh, String name,String type,String time) {

        if(CollectionUtils.isEmpty(parse)){
            return null;
        }

        List<SharesData> sharesDatas=new ArrayList<>();
        for (Object o : parse) {

            String[] splito = o.toString().split(",");

            if(DateUtil.compareDate(splito[0],time)){
                continue;
            }
            BigDecimal spj = new BigDecimal(splito[2]);//收盘价
            BigDecimal kpj = new BigDecimal(splito[1]);//开盘价
            BigDecimal zgj = new BigDecimal(splito[3]);//开盘价
            BigDecimal zdj = new BigDecimal(splito[4]);//开盘价

            SharesData sharesData = new SharesData();
            sharesData.setCjl(splito[5]);//成交量
            sharesData.setName(name);
            sharesData.setCode(szorsh);

            sharesData.setTime(splito[0]);
            sharesData.setHPrice(zgj);
            sharesData.setKPrice(kpj);
            sharesData.setDPrice(zdj);
            sharesData.setCPrice(spj);
            sharesData.setType(type);

            sharesDatas.add(sharesData);
        }
        return  sharesDatas;

    }

    /**
     * 获取周数据
     */
    @Override
    public void getWeekData() {


        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);


        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            System.out.println(szorsh);
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);
            System.out.println(szorsh+"="+sharesCode.getId());
            String url="";
            if(szorsh.contains("sz")){

                url="http://push2his.eastmoney.com/api/qt/stock/kline/get?" +
                        "cb=jQuery11240790555926397122_"+new Date().getTime()+
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&ut=7eea3edcaed734bea9cbfc24409ed989&klt=102&fqt=1" +
                        "&secid=0." + substring+
                        "&beg=0&end=20500000&_="+new Date().getTime();

            }

            if(szorsh.contains("sh")){
                url="http://28.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_"+new Date().getTime()+
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=102&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=this.saveCjl(parse,szorsh,name, SharesConstan.WEEK
                        ,DateUtil.getYMDByDaysAgo(180));
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    this.insertBatch(sharesDatas);
                    //上周收盘价
                    SharesData sharesData = sharesDatas.get(sharesDatas.size() - 1);
                    BigDecimal kPrice = sharesData.getCPrice();
                    sharesCode.setZkPrice(kPrice.toString());
                }
            }catch (Exception e){
                System.out.println(szorsh + "周收盘价err");
                e.printStackTrace();
            }
        }
        sharesDetailService.updateBatchById(sharesDetails);
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     * 获取月数据
     */
    @Override
    public void getMonthData() {
        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);

            System.out.println(szorsh+"="+sharesCode.getId());
            if(substring.startsWith("688")){
                continue;
            }
            String url="";
            if(szorsh.contains("sz")){

                url="http://push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery11240790555926397122_"+new Date().getTime()+
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=" +
                        "f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&ut=" +
                        "7eea3edcaed734bea9cbfc24409ed989&klt=103&fqt=1" +
                        "&secid=0." +substring +
                        "&beg=0&end=20500000&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://27.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408635039957089012_"+new Date().getTime()+
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1" +
                        "=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt" +
                        "=103&fqt=0&end=20500101&lmt=120&_="+new Date().getTime();
            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas=this.saveCjl(parse,szorsh,name, SharesConstan.MONTH
                        ,DateUtil.getYMDByDaysAgo(360));
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    this.insertBatch(sharesDatas);
                    //上月收盘价
                    SharesData sharesData = sharesDatas.get(sharesDatas.size() - 2);
                    BigDecimal kPrice = sharesData.getCPrice();
                    sharesCode.setYkPrice(kPrice.toString());
                }
            }catch (Exception e){
                System.out.println(szorsh + "月收盘价err");
                e.printStackTrace();
            }
        }
        sharesDetailService.updateBatchById(sharesDetails);
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**、
     * 计算历史周涨幅
     */
    @Override
    public void getzzf() {

        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesDetail : sharesDetails) {
            List<SharesData> upDataShares=new ArrayList<>();
            Wrapper<SharesData> wr=new EntityWrapper<>();
            wr.eq("type", SharesConstan.WEEK);
            wr.gt("time",DateUtil.getYMDByDaysAgo(120));
            wr.eq("code",sharesDetail.getCode());
            System.out.println(sharesDetail.getCode());
            List<SharesData> sharesDatas = this.selectList(wr);

            List<SharesData> savez=new ArrayList<>();
            for (int i=1;i<sharesDatas.size();i++){
                SharesData sharesData1 = sharesDatas.get(i - 1);
                BigDecimal cPrice1 = sharesData1.getCPrice();

                SharesData sharesData = sharesDatas.get(i);
                BigDecimal cPrice = sharesData.getCPrice();

                if(cPrice.compareTo(cPrice1)==-1){
                    continue;
                }
                BigDecimal mzf = MeUtils.calculateTrend(cPrice.toString(), cPrice1.toString());
                sharesData.setZdf(mzf.toString());
                upDataShares.add(sharesData);
                savez.add(sharesData);

            }
            List<SharesZdfVo> zdfVos=new ArrayList<>();
            for (SharesData sharesData : savez) {
                SharesZdfVo sharesZdfVo = new SharesZdfVo();
                sharesZdfVo.setD(sharesData.getTime());
                sharesZdfVo.setZdf(sharesData.getZdf());
                zdfVos.add(sharesZdfVo);
            }
            String s = JSONArray.toJSONString(zdfVos);
            sharesDetail.setZzf(s);
            //更新周涨幅数据，可删除
            if(!CollectionUtils.isEmpty(upDataShares)){
                this.updateBatchById(upDataShares);
            }
            sharesDetailService.updateById(sharesDetail);
        }

//        sharesDetailService.updateBatchById(sharesDetails);


    }

    /**
     * 计算历史月涨幅
     */
    @Override
    public void getyzf() {

        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status",88);
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesDetail : sharesDetails) {
            List<SharesData> upDataShares=new ArrayList<>();
            Wrapper<SharesData> wr=new EntityWrapper<>();
            wr.eq("type", SharesConstan.MONTH);
            wr.gt("time",DateUtil.getYMDByDaysAgo(360));
            wr.eq("code",sharesDetail.getCode());
            System.out.println(sharesDetail.getCode());
            List<SharesData> sharesDatas = this.selectList(wr);

            List<SharesData> savey=new ArrayList<>();
            //计算历史月涨幅
            for (int i=1;i<sharesDatas.size()-1;i++){
                SharesData sharesData1 = sharesDatas.get(i - 1);
                BigDecimal cPrice1 = sharesData1.getCPrice();
                SharesData sharesData = sharesDatas.get(i);
                BigDecimal cPrice = sharesData.getCPrice();
                if(cPrice.compareTo(cPrice1)==-1){
                    continue;
                }
                BigDecimal mzf = MeUtils.calculateTrend(cPrice.toString(), cPrice1.toString());
                sharesData.setZdf(mzf.toString());
                upDataShares.add(sharesData);
                savey.add(sharesData);
            }
            //保存历史月涨幅
            List<SharesZdfVo> zdfVos=new ArrayList<>();
            if(!CollectionUtils.isEmpty(savey)){
                for (SharesData sharesData : savey) {
                    SharesZdfVo sharesZdfVo = new SharesZdfVo();
                    sharesZdfVo.setD(sharesData.getTime());
                    sharesZdfVo.setZdf(sharesData.getZdf());
                    zdfVos.add(sharesZdfVo);
                }
            }
            String s = JSONArray.toJSONString(zdfVos);
            sharesDetail.setYzf(s);
            sharesDetailService.updateById(sharesDetail);
            if(!CollectionUtils.isEmpty(upDataShares)){
                this.updateBatchById(upDataShares);
            }
        }
//        sharesDetailService.updateBatchById(sharesDetails);

    }

    /**
     * 获取最近一年左右的数据
     */
    @Override
    public void getDataByYear() {
        Wrapper<SharesData> wer=new EntityWrapper<>();
        wer.eq("type",SharesConstan.ZDF);
        this.delete(wer);

        long st = System.currentTimeMillis();
        Wrapper<SharesDetail> wrd=new EntityWrapper<>();
        wrd.eq("status","88");
        List<SharesDetail> sharesDetails = sharesDetailService.selectList(wrd);

        for (SharesDetail sharesCode : sharesDetails) {
            String szorsh = sharesCode.getCode();
                System.out.println(szorsh);
            String name = sharesCode.getName();
            String substring = szorsh.substring(2);
            String url="";
            if(szorsh.contains("sz")){

                url="http://push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112406700133011037424_"+new Date().getTime()+
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2" +
                        "=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&ut" +
                        "=7eea3edcaed734bea9cbfc24409ed989&klt=101&fqt=1" +
                        "&secid=0." +substring +
                        "&beg=0&end=20500000&_="+new Date().getTime();

//                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
//                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
//                        "&secid=0." +substring +
//                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
//                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
//                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
//                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();
            }

            if(szorsh.contains("sh")){
                url="http://49.push2his.eastmoney.com/api/qt/stock/kline/get" +
                        "?cb=jQuery112408735255525730368_" + +new Date().getTime()+
                        "&secid=1." +substring +
                        "&ut=fa5fd1943c7b386f172d6893dbfba10b" +
                        "&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6" +
                        "&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61" +
                        "&klt=101&fqt=1&end=20500101&lmt=120&_="+new Date().getTime();

            }

            try{
                HttpGet get=new HttpGet(url);
                CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
                String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
                int rIndex = result.indexOf("(");
                String resultStr = result.substring(rIndex + 1, result.length() - 2);
                JSONObject datas2 = JSONObject.parseObject(resultStr);
                String data = datas2.getString("data");
                String klines = JSONObject.parseObject(data).getString("klines");
                List<Object> parse = (List<Object>) JSON.parse(klines);
                List<SharesData> sharesDatas = this.saveCjl(parse, szorsh, name, SharesConstan.ZDF, DateUtil.getYMDByDaysAgo(360*5));

                List<SharesData> hshares=new ArrayList<>();
                if(!CollectionUtils.isEmpty(sharesDatas)){
                    for(int i=1;i<sharesDatas.size();i++){
                        SharesData vo0 = sharesDatas.get(i - 1);
                        SharesData vo1 = sharesDatas.get(i);
                        BigDecimal cPrice1 = vo1.getCPrice();
                        BigDecimal cPrice0 = vo0.getCPrice();
                        BigDecimal zdf = MeUtils.calculateTrend(cPrice1.toString(), cPrice0.toString());
                        ////判断涨幅是否大于10
                        if(zdf.compareTo(new BigDecimal(0.1))==1){
                            vo1.setZdf(MeUtils.getPercent(zdf.toString()));
                            hshares.add(sharesDatas.get(i));
                        }
                    }
                }
                if(!CollectionUtils.isEmpty(hshares)){
                    this.insertBatch(hshares);
                }

            }catch (Exception e){
                e.printStackTrace();
            }
        }
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     * 获取跟涨的数据
     */
    @Override
    public void getZdfShares() {
        Wrapper<SharesData> wr=new EntityWrapper<>();
        wr.eq("type",SharesConstan.ZDF);
        wr.gt("time","2018-01-01");
        List<SharesData> sharesData = this.selectList(wr);

        Map<String,List<SharesData>> sharesMap=new HashMap<>();
        Map<String,List<SharesData>> timeMap=new HashMap<>();
        for (SharesData sharesDatum : sharesData) {
            String time = sharesDatum.getTime();
            List<SharesData> vo = timeMap.get(time);
            if(!CollectionUtils.isEmpty(vo)){
                vo.add(sharesDatum);
                timeMap.put(time,vo);
            }else{
                List<SharesData> to=new ArrayList<>();
                to.add(sharesDatum);
                timeMap.put(time,to);
            }
        }

        for (SharesData sharesDatum : sharesData) {
            String time = sharesDatum.getTime();
            String name = sharesDatum.getName();
            String code = sharesDatum.getCode();
            String trim = code.trim();
            List<SharesData> vo = timeMap.get(time);
            List<SharesData> to = sharesMap.get(trim);
            if(!CollectionUtils.isEmpty(to)){
                if(!CollectionUtils.isEmpty(vo)){
                    to.addAll(vo);
                }
            }else{
                if(!CollectionUtils.isEmpty(vo)){
                    List<SharesData> dto=new ArrayList<>();
                    dto.addAll(vo);
                    sharesMap.put(trim,dto  );
                }
            }
        }

        SharesConstan.HIGT_SHARES_MAP=sharesMap;

//        List<SharesData> sharesData1 = sharesMap.get("幸福蓝海");
//        if(!CollectionUtils.isEmpty(sharesData1)){
//            Map<String,Integer> numap=new HashMap<>();
//            for (SharesData data : sharesData1) {
//                String name = data.getName();
//                Integer integer = numap.get(name);
//                if(null==integer){
//                    numap.put(name,1);
//                }else{
//                    numap.put(name,integer+1);
//                }
//            }
//
//            for (String s : numap.keySet()) {
//                System.out.println(s+":"+numap.get(s));
//            }
//        }
//        System.out.println("end");

    }

    @Override
    public void getTsData() {
        Wrapper<HintShares> wr=new EntityWrapper<>();
        wr.isNotNull("ts_time");
        wr.orderBy("id");
        List<HintShares> hintSharesList = hintSharesService.selectList(wr);

        Wrapper<SharesData> szwr=new EntityWrapper<>();
        szwr.eq("type",SharesConstan.SZ);
        List<SharesData> sharesData = this.selectList(szwr);

        Map<String,SharesData>  szMap=new HashMap<>();
        for (SharesData sharesDatum : sharesData) {
            String time = sharesDatum.getTime();
            szMap.put(time,sharesDatum);
        }

        Set<String> setTime=new HashSet<>();
//        DateUtil
        Map<String,List<HintShares>> tMap=new TreeMap<>();
        Map<String,Object> allMap=new HashMap<>();
        for (HintShares hintShares : hintSharesList) {
            Long tsTime = hintShares.getTsTime();
            String time = hintShares.getTime();
            setTime.add(time);

            List<String> times=new ArrayList<>();
//            times.add("09:30");
//            times.add("09:35");
            times.add("09:40");
            times.add("09:50");
            times.add("10:00");
            times.add("10:10");
            times.add("10:20");
            times.add("10:30");
            times.add("10:40");
            times.add("10:50");
            times.add("11:00");

            for (String timeVo : times) {
                if(DateUtil.judgeIsSetBiddingTime2("9:20",timeVo,tsTime)){
                    List<HintShares> vo = tMap.get(time+"~"+timeVo);
                    if(!CollectionUtils.isEmpty(vo)){
                        vo.add(hintShares);
                    }else{
                        List<HintShares> to=new ArrayList<>();
                        to.add(hintShares);
                        tMap.put(time+"~"+timeVo,to);
                    }
                }
            }
        }

        Wrapper<HintNum> delwr=new EntityWrapper<>();
        hintNumService.delete(delwr);

        List<HintNum> hintNums=new ArrayList<>();
        for (String key : tMap.keySet()) {
            try {
//                System.out.println(key+"====="+tMap.get(key).size()+"==sz: "+szMap.get(key.split("~")[0]).getZdf());
                HintNum hintNum=new HintNum()   ;
                hintNum.setTime(key.split("~")[0]);
                hintNum.setNum(tMap.get(key).size());
                hintNum.setHour(key.split("~")[1]);
                hintNum.setZdf( szMap.get(key.split("~")[0]).getZdf());
                hintNums.add(hintNum);
            }catch (Exception e){

            }
        }
        if(!CollectionUtils.isEmpty(hintNums)){
            hintNumService.insertBatch(hintNums);
        }


    }

    /**
     * 获取创业板指
     * {
     *         //http://4.push2his.eastmoney.com/api/qt/stock/kline/get?cb=jQuery33108670220148479237_1644488196610&secid=0.399006&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=101&fqt=1&beg=0&end=20500101&smplmt=1373&lmt=1000000&_=1644488196614
     *     }
     */
    @Override
    public void getsz() {
        Wrapper<SharesData> wer=new EntityWrapper<>();
        wer.eq("type",SharesConstan.SZ);
        this.delete(wer);

        long st = System.currentTimeMillis();

        String szorsh = "399006";
        System.out.println(szorsh);
        String name = "创业板指";
        String url="";
//            url="http://9.push2his.eastmoney.com/api/qt/stock/kline/get" +
//                    "?cb=jQuery33105853835685669839_1644488471673&secid=0.399006" +
//                    "&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=101&fqt=1" +
//                    "&beg=0&end=20500101&smplmt=1373&lmt=1000000&_=1644488471675";

//            url="http://52.push2his.eastmoney.com/api/qt/stock/kline/get?cb=jQuery3510262640945778986_1644820041440&secid=0.399006&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=101&fqt=1&beg=0&end=20500101&smplmt=460&lmt=1000000&_=1644820041452";

            url="http://16.push2his.eastmoney.com/api/qt/stock/kline/get?cb=jQuery3510262640945778986_1644820041425&secid=0.399006&ut=fa5fd1943c7b386f172d6893dbfba10b&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5%2Cf6&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58%2Cf59%2Cf60%2Cf61&klt=101&fqt=1&end=20500101&lmt=120&_=1644820041517";
            try{
            HttpGet get=new HttpGet(url);
            CloseableHttpResponse execute = HttpClient5Utils.httpclient.execute(get);
            String result = EntityUtils.toString(execute.getEntity(), "UTF-8");
            int rIndex = result.indexOf("(");
            String resultStr = result.substring(rIndex + 1, result.length() - 2);
            JSONObject datas2 = JSONObject.parseObject(resultStr);
            String data = datas2.getString("data");
            String klines = JSONObject.parseObject(data).getString("klines");
            List<Object> parse = (List<Object>) JSON.parse(klines);
            List<SharesData> sharesDatas = this.saveCjl(parse, szorsh, name, SharesConstan.SZ, DateUtil.getYMDByDaysAgo(100));

            List<SharesData> hshares=new ArrayList<>();
            if(!CollectionUtils.isEmpty(sharesDatas)){
                for(int i=1;i<sharesDatas.size();i++){
                    SharesData vo0 = sharesDatas.get(i - 1);
                    SharesData vo1 = sharesDatas.get(i);
                    BigDecimal cPrice1 = vo1.getCPrice();
                    BigDecimal cPrice0 = vo0.getCPrice();
                    BigDecimal zdf = MeUtils.calculateTrend(cPrice1.toString(), cPrice0.toString());
                    ////判断涨幅是否大于10
//                    if(zdf.compareTo(new BigDecimal(0.1))==1){
                        vo1.setZdf(MeUtils.getPercent(zdf.toString()));
                        hshares.add(sharesDatas.get(i));
//                    }
                }
            }
            if(!CollectionUtils.isEmpty(hshares)){
                this.insertBatch(hshares);
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        long en = System.currentTimeMillis();
        long l = (en - st)/1000;
        System.out.println(l);
    }

    /**
     *
     */
    @Override
    public void jData() {
        Wrapper<HintNum> wr=new EntityWrapper<>();
        wr.orderBy("id");
        List<HintNum> hintNums = hintNumService.selectList(wr);
        for (HintNum hintNum : hintNums) {

        }
    }
}
